`
https://leetcode.cn/problems/remove-nth-node-from-end-of-list/
`

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} n
 * @return {ListNode}
 */
var removeNthFromEnd = function (head, n) {
  // 右指针先走 n+1 步，左右指针一起走，右指针走到头，左指针的下一个就是要删除的节点
  const dummp = {
    next: head
  }
  let l = dummp
  let r = dummp
  for (let i = 0; i < n + 1; i++) {
    r = r.next
  }
  if (!r) return l.next.next
  while (r) {
    l = l.next
    r = r.next
  }
  l.next = l.next.next
  return head

};